package com.werdior.admin.www;

import com.google.common.collect.Maps;
import com.werdior.common.advice.BaseMultiController;
import com.werdior.common.util.CamelNameUtils;
import com.werdior.common.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;


/**
 * Created by weirdor on 2017/12/27.
 */
@Controller
@RequestMapping("/view")
public class WebViewController extends BaseMultiController {

    @RequestMapping(value = "/admin/{admin}/list")
    public ModelAndView moduleList(@PathVariable("admin") String module){
        Map<String,Object> context = Maps.newHashMap();
        context.put("admin", module);
        String view = "/page/admin/" +StringUtils.trim(CamelNameUtils.camelToUnderline(module))+"/"+ StringUtils.trim(CamelNameUtils.camelToUnderline(module)) + "_list";
        return new ModelAndView(view, context);
    }

    @RequestMapping(value = "/admin/{admin}/edit")
    public ModelAndView moduleEdit(@PathVariable("admin") String module){
        Map<String,Object> context = Maps.newHashMap();
        context.put("admin", module);
        String view = "/page/admin/" +StringUtils.trim(CamelNameUtils.camelToUnderline(module))+"/"+ StringUtils.trim(CamelNameUtils.camelToUnderline(module)) + "_edit";
        return new ModelAndView(view, context);
    }

    @RequestMapping(value = "/admin/{admin}/add")
    public ModelAndView moduleAdd(@PathVariable("admin") String module){
        Map<String,Object> context = Maps.newHashMap();
        context.put("admin", module);
        String view = "/page/admin/" +StringUtils.trim(CamelNameUtils.camelToUnderline(module))+"/"+ StringUtils.trim(CamelNameUtils.camelToUnderline(module)) + "_add";
        return new ModelAndView(view, context);
    }
}
